<?php

/**
 * This is the model class for table "Rate".
 *
 * The followings are the available columns in table 'Rate':
 * @property string $id
 * @property string $raterId
 * @property string $commentId
 * @property string $type
 * @property string $created
 */
class Rate extends CActiveRecord
{
	const TYPE_UP = 1;
	const TYPE_DOWN = 2;

	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className the class name
	 * @return Rate the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Rate';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('raterId, commentId, type', 'required'),
			array('raterId, commentId, type', 'length', 'max'=>10),
			array('created', 'safe'),
			array('id, raterId, commentId, type, created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
		);
	}

	/**
	 * @return array attached behaviors.
	 */
	public function behaviors()
	{
		return array(
			'ext.auditbehavior.AuditBehavior',
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('label','Id'),
			'raterId' => Yii::t('label','Rater'),
			'commentId' => Yii::t('label','Comment'),
			'type' => Yii::t('label','Type'),
			'created' => Yii::t('label','Created'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('t.id',$this->id,true);
		$criteria->compare('t.raterId',$this->raterId,true);
		$criteria->compare('t.commentId',$this->commentId,true);
		$criteria->compare('t.type',$this->type,true);
		$criteria->compare('t.created',$this->created,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * @return array the valid rate types.
	 */
	public static function getValidTypes()
	{
		return array(self::TYPE_UP, self::TYPE_DOWN);
	}
}